﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using FDEECommonTools;
using FDEEInterface;
using FDEEPublicFunc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FDEEDrawingModels
{
    public class DrawingPlinthList
    {
        public static void DrawPlinthBatch(Database db, string dwgPath, string plinthCoorPath, string blockParaPath, int stNo, int endNo, string pierList, string tAPara, string tBPara, string iAPara, string iBPara,ref string pierdiv, string title = "MAINLINE",string tkPath="")
        {
            double scale = 1;
           Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Extents2d extA = new Extents2d(Point2d.Origin, Point2d.Origin);
            Extents2d extB = new Extents2d(Point2d.Origin, Point2d.Origin);
            Extents2d extC = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin.Convert2D(0, -2 * scale);
            Point2d M1 = CT;
            ext = new Extents2d(M1, M1);
            System.Data.DataTable dtA = new System.Data.DataTable();
            System.Data.DataTable dtB = new System.Data.DataTable();
            //System.Data.DataTable dt = CVSTools.OpenCSV(@"C:\Users\huajie\Desktop\FDEE_Data\295~335参数表.csv");
            //System.Data.DataTable dt = new FDEECommonTools.ExcelHelper().ExcelToTableForXLSX(@"C:\Users\huajie\Desktop\FDEE_Data\Banani参数表.xlsx");
            System.Data.DataTable dt = new FDEECommonTools.ExcelHelper().ExcelToTableForXLSX(blockParaPath);
           //System.Data.DataTable dtP = new System.Data.DataTable();
           //DataView dv = dt.DefaultView;
           //dtP = dt;
           int i = 0;
            int pageNo = 2;
            if (dt.Rows.Count > 0)
            {
                pierdiv = dt.Rows[stNo]["墩号"].ToString() + "-" + dt.Rows[endNo]["墩号"].ToString();
                //string title = "MAINLINE";
                //string title = "RAMP BANANI EX-2";//修改
                #region 292-335
                //for (int m = 0; m < 5; m++)
                //for (int m = 5; m < 13; m++)
                //for (int m = 13; m < 21; m++)
                //for (int m = 21; m < 28; m++)
                ////for (int m = 30; m < 32; m++)
                //for (int m = 28; m < 35; m++)
                //for (int m = 35; m < 41; m++)
                #endregion
                for (int m = stNo; m <= endNo; m++)
                {
                    double side = double.Parse(dt.Rows[m]["左边距"].ToString());
                    double rside = double.Parse(dt.Rows[m]["右边距"].ToString());
                    double width = double.Parse(dt.Rows[m]["总墩距"].ToString()) + rside + side;
                    string piertype = dt.Rows[m]["墩柱类别"].ToString();
                    string piername = dt.Rows[m]["墩号"].ToString();
                    //string piertype = tr["墩柱类别"].ToString();
                    //if (width > 40)
                    //    scale = 120;
                    //else if (width > 36)
                    //    scale = 110;
                    //else 
                   if (width > 26)
                        scale = 100;
                    else
                        scale = 80;
                    ext = new Extents2d(M1.Convert2D(420 * i, -297), M1.Convert2D(420 * i, -297));
                    extA = new Extents2d(M1.Convert2D(420 * i, -297 - 10), M1.Convert2D(420 * i, -297 - 10));
                    extB = new Extents2d(M1.Convert2D(420 * i, -297 - 30), M1.Convert2D(420 * i, -297 - 30));
                    extC = new Extents2d(M1.Convert2D(420 * i, -297 - 30 - 10), M1.Convert2D(420 * i, -297 - 30 - 10));
                    DrawingPlinth(db, ref ext, ref extA, ref extB, ref extC, M1.Convert3D(420 * i, -297), M1.Convert3D(420 * i, -297 - 10), M1.Convert3D(420 * i, -297 - 30), M1.Convert3D(420 * i, -297 - 30 - 10),
                        Extensions.curFont, scale, dt.Rows[m], dwgPath,  plinthCoorPath, tAPara, tBPara, iAPara, iBPara, title);
                    string content = "Notes:\\P"
+ "1. All dimensions are in m unless otherwise indicated.\\P"
+ "2. The contractor shall verify all dimensions on site and resolve all discrepancies with the \\P engineer & architect before commencement of work."
+ "3. All the produced unsuitable material shall be transport to the designate disposal area in a properly manner.\\P"
+ "4. All the site activities and operations shall follow the requirement of the approved Health and Safety \\P Management Plan strictly."
+ "5. Concrete shall have the minimum 45MPa of cylinder compressive strength at 28 days.\\P"
+ "6. Reinforcement steel shall have the minimum yield strength 500MPa.\\P"
+ "7. Concrete cover shall be 0.050m for cross beam.";
        
                    for (int n = 0; n < pageNo; n++)
                    {
                     
                        Extents2d ext0 = new Extents2d(Point2d.Origin, Point2d.Origin);
                        if (n < pageNo - 1)
                        {
                     
                            Common.CreatPlinthLayoutNew(db, "垫石构造", ext, extA, scale, pageNo - 1, i, n,false, tkPath);
                           
                        }
                        else
                        {
                            Common.CreatPlinthLayoutNew(db, "垫石构造", extB, extC, scale, 1, i, n,false, tkPath);
                      
                        }
                        try
                        {
                            string _blcName = piertype;
                            db.CopyBlockFromFile(dwgPath, _blcName);
                            BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(17.85 + 420 * n, 23.3 - 297 * i), 1, _blcName, dwgPath, 0, false);
                        }
                        catch
                        {

                        }
                        TextPloter.PrintMultiText(db, ref ext0, Point2d.Origin.Convert3D(17.85 + 85 + 420 * n, 23.3 + 68 - 297 * i), content, 1, 3, 210, false);
                    }
                   
                    i++;
                }

            }
        }

        public static void DrawingPlinth(Database db, ref Extents2d ext, ref Extents2d extA, ref Extents2d extB, ref Extents2d extC, Point3d startPoint, Point3d startAPoint, Point3d startBPoint, Point3d startCPoint,
string txtStyle, double scale, System.Data.DataRow tr,  string _dwgPath, string plinthCoorPath, string tAPara, string tBPara, string iAPara, string iBPara, string title= "MAINLINE")
        {
            List<string> taParas = tAPara.Split('|').ToList();
            List<string> tbParas = tBPara.Split('|').ToList();
            List<string> iaParas = iAPara.Split('|').ToList();
            List<string> ibParas = iBPara.Split('|').ToList();
            if (!DimStyleTool.CheckDimStyleExists(scale))
            {
                DimStyleTool.CreateModifyDimStyle(scale);
            }
            double tSize = 0.15;

            if(scale==80)
                tSize = (2 *  scale) / 1000;
            else if (scale == 100)
                tSize = (2 *  scale) / 1000;
            else
                tSize = (2 * scale) / 1000;

            double lwidth = double.Parse(tr["左墩距"].ToString());
            double side = double.Parse(tr["左边距"].ToString());
            double rside = double.Parse(tr["右边距"].ToString());
            double width = double.Parse(tr["总墩距"].ToString()) + rside+ side;
            double bottomW = double.Parse(tr["底宽"].ToString());
            double topW = double.Parse(tr["顶宽"].ToString());
            double height = double.Parse(tr["总高"].ToString());
            double calculatedHeight = double.Parse(tr["底高"].ToString());
            double plinthHeight = double.Parse(tr["支座距"].ToString());
            string piername = tr["墩号"].ToString();
            string piertype = tr["墩柱类别"].ToString();
            string AString = tr["垫石A"].ToString();
            string BString = tr["垫石B"].ToString();

            string tapara = taParas.Find(item => item.Contains(piername));
            string[] taparas = null;
            if (tapara != null)
                taparas = tapara.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(':');
            string tbpara = tbParas.Find(item => item.Contains(piername));
            string[] tbparas = null;
            if (tbpara != null)
                tbparas = tbpara.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(':');
            string iapara = iaParas.Find(item => item.Contains(piername));
            string[] iaparas = null;
            if (iapara != null)
                iaparas = iapara.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(':');
            string ibpara = ibParas.Find(item => item.Contains(piername));
            string[] ibparas = null;
            if (ibpara != null)
                ibparas = ibpara.Replace("(","").Replace(")", "").Replace("（", "").Replace("）", "").Split(':');

            List<double> Alist = new List<double>();
            List<double> Blist = new List<double>();
            for (int i = 0; i < AString.Split('+').Length; i ++)
            {
                string value = AString.Split('+')[i];
                if (value.Contains("*"))
                {
                    int count = int.Parse(value.Split('*')[1]);
                    double length= double.Parse(value.Split('*')[0]);
                    for(int j=0;j< count;j++)
                    {
                        Alist.Add(length);
                    }
                }
                else
                {
                    Alist.Add(double.Parse(value));
                }
            }
            for (int i = 0; i < BString.Split('+').Length; i++)
            {
                string value = BString.Split('+')[i];
                if (value.Contains("*"))
                {
                    int count = int.Parse(value.Split('*')[1]);
                    double length = double.Parse(value.Split('*')[0]);
                    for (int j = 0; j < count; j++)
                    {
                        Blist.Add(length);
                    }
                }
                else
                {
                    Blist.Add(double.Parse(value));
                }
            }
            #region 平面绘制
            string str1 = string.Format("PIER TYPE \"{0}\" FOR {1} OF {2} (PLAN VIEW) ", piertype, piername,title);
            string str2 = "1:" + scale + "@A3";
            TextPloter.PrintScaleDoubleSideTextNew(db, startPoint.Convert2D(0, 2.4), tSize * 1.25, str1, str2, ref ext, 1, Extensions.curFont);
            #region 1.外轮廓绘制
            //1、绘制
            List<Point2d> ptL = new List<Point2d>();
            Point2d pt1 = startPoint.Convert2D(-width * 0.5);
            Point2d pt2 = pt1.Convert2D(0,-bottomW);
            Point2d pt3 = pt2.Convert2D(width);
            Point2d pt4 = pt3.Convert2D(0, bottomW);
            ptL.Add(pt1);
            ptL.Add(pt2);
            ptL.Add(pt3);
            ptL.Add(pt4);
            PolylinePloter.AddPolylineByList(db,ref ext, ptL,"细线",4,true);

            ptL = new List<Point2d>();
            double h = (bottomW - topW) * 0.5;
            Point2d p0 = pt1.Convert2D(0.2, 0);
            Point2d p1 = p0.Convert2D(0, -h);
            Point2d p2 = p1.Convert2D(width - 0.4, 0); 
            Point2d p3 = p2.Convert2D(0, h);
            ptL.Add(p0);
            ptL.Add(p1);
            ptL.Add(p2);
            ptL.Add(p3);
            PolylinePloter.AddPolylineByList(db, ref ext, ptL, "细线", 4, false);

            ptL = new List<Point2d>();
            Point2d p00 = pt2.Convert2D(0.2, 0);
            Point2d p01 = p00.Convert2D(0, h);
            Point2d p02 = p01.Convert2D(width - 0.4, 0);
            Point2d p03 = p02.Convert2D(0, -h);
            ptL.Add(p00);
            ptL.Add(p01);
            ptL.Add(p02);
            ptL.Add(p03);
            PolylinePloter.AddPolylineByList(db, ref ext, ptL, "细线", 4, false);

            Dictionary<string, Dictionary<string, string>> dicA = new Dictionary<string, Dictionary<string, string>>();
            Dictionary<string, string> dicT = new Dictionary<string, string>();

            dicT = new Dictionary<string, string>();
  
            dicT.Add("Bearing", "string");
            dicA.Add("CL", dicT);
            string _blcName = "CL";
            db.CopyBlockFromFile(_dwgPath, _blcName);          
            BlockTool.InsertBlockReference(pt3.Convert3D(0.6 +0.15, 0.5 * h), tSize * 1.6, _blcName, _dwgPath, dicA, null, ref ext);
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(pt4.Convert3D(0.6  + 0.15, -0.5 * h), tSize * 1.6, _blcName, _dwgPath, dicA, null, ref ext);

            dicA = new Dictionary<string, Dictionary<string, string>>();
            dicT = new Dictionary<string, string>();
            dicT.Add("Pier", "string");
            dicA.Add("CL", dicT);           
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(pt4.Convert3D(0.6 + 0.15, -bottomW * 0.5), tSize * 1.6, _blcName, _dwgPath, dicA, null, ref ext);

            DimPloter.AddZYBJ("Ⅰ", pt1.Convert3D(-1.2 - 0.15, -0.25 * h), ref ext, 0.05, tSize, true);
            DimPloter.AddZYBJ("Ⅱ", pt2.Convert3D(-1.2 - 0.15, 0.25 * h), ref ext, 0.05, tSize, true);
            DimPloter.AddZYBJ("Ⅰ", pt4.Convert3D(0.3 + 0.15, -0.25 * h), ref ext, 0.05, tSize, false);
            DimPloter.AddZYBJ("Ⅱ", pt3.Convert3D(0.3 + 0.15, 0.25 * h), ref ext, 0.05, tSize, false);

            //DimPloter.AddZYBJ("Ⅰ", pt4.Convert3D(0.3  + 0.15, -0.25 * h), ref ext, 0.05, tSize, true);
            //DimPloter.AddZYBJ("Ⅱ", pt3.Convert3D(0.3 + 0.15, 0.25 * h), ref ext, 0.05, tSize, true);
            //DimPloter.AddZYBJ("Ⅰ", pt1.Convert3D(-1.1  - 0.15, -0.25 * h), ref ext, 0.05, tSize, false);
            //DimPloter.AddZYBJ("Ⅱ", pt2.Convert3D(-1.1  - 0.15, 0.25 * h), ref ext, 0.05, tSize, false);


            PolylinePloter.AddPolyline(db, ref ext, pt1.Convert2D(0,-bottomW*0.5), pt4.Convert2D(0.2, -bottomW * 0.5), 0, 0, 0, 0, "中心线", 5,2.5);
            PolylinePloter.AddPolyline(db, ref ext, pt1.Convert2D(0.2, -h * 0.5), pt4.Convert2D(0.2, -h * 0.5), 0, 0, 0, 0, "中心线", 5, 2.5);
            PolylinePloter.AddPolyline(db, ref ext, pt2.Convert2D(0.2, h * 0.5), pt3.Convert2D(0.2, h * 0.5), 0, 0, 0, 0, "中心线", 5, 2.5);

            PolylinePloter.AddPolyline(db, ref ext, pt1.Convert2D(side, 1.9), pt2.Convert2D(side, -1), 0, 0, 0, 0, "中心线", 5, 2.5);
            dicA = new Dictionary<string, Dictionary<string, string>>();
            dicT = new Dictionary<string, string>();
            dicT.Add("Column", "string");
            dicA.Add("CL", dicT);
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(pt1.Convert3D(side, 1.9), tSize * 2, _blcName, _dwgPath, dicA, null, ref ext);
            PolylinePloter.AddPolyline(db, ref ext, startPoint.Convert2D(0, 1.9), startPoint.Convert2D(0, -bottomW-1), 0, 0, 0, 0, "中心线", 5, 2.5);
            dicA = new Dictionary<string, Dictionary<string, string>>();
            dicT = new Dictionary<string, string>();
            dicT.Add("Cross Beam", "string");
            dicA.Add("CL", dicT);
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(startPoint.Convert3D(0, 1.9), tSize * 2, _blcName, _dwgPath, dicA, null, ref ext);
            PolylinePloter.AddPolyline(db, ref ext, pt3.Convert2D(-rside, -1), pt4.Convert2D(-rside, 1.9), 0, 0, 0, 0, "中心线", 5, 2.5);
            dicA = new Dictionary<string, Dictionary<string, string>>();
            dicT = new Dictionary<string, string>();
            dicT.Add("Column", "string");
            dicA.Add("CL", dicT);
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(pt4.Convert3D(-rside, 1.9), tSize * 2, _blcName, _dwgPath, dicA, null, ref ext);
            #endregion

            #region 垫石绘制
            double len = 0;
            for (int i = 0; i < Alist.Count; i++)
            {
                len += Alist[i];
                Point2d ptB = pt4.Convert2D(-len, -h * 0.5);
                //PolylinePloter.AddPloy4(db, ref ext, ptB.Convert2D(0, 0.5 * 0.5), 0.6 * 0.5, 0.6 * 0.5, 0.5);
                _blcName = "pPlinth"+scale;
                dicA = new Dictionary<string, Dictionary<string, string>>();
                dicT = new Dictionary<string, string>();
                dicT.Add((i+1).ToString(), "string");
                dicA.Add("A", dicT);
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(ptB.Convert3D(), 1, _blcName, _dwgPath, dicA, null, ref ext);
                //DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5, 0.5 * 0.5), ptB.Convert2D(-0.6*0.5, 0.5 * 0.5 - 0.5).Convert3D(0,-0.35), scale);
                //DimPloter.DimAli(db, ref ext, ptB.Convert3D(0, 0.5 * 0.5), ptB.Convert3D(0, 0.5 * 0.5 - 0.5), ptB.Convert2D(-0.6 * 0.5, 0.5 * 0.5 - 0.5).Convert3D(-0.2), scale);
                //挡块
                if (piername.Contains("297")|| piername.Contains("298") || piername.Contains("RP-15") || piername.Contains("RP-16") || piername.Contains("RP-17"))
                {
                    if (i == 0)
                    {
                        DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7-tSize*2), scale);
                        DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(Alist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                        DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 , 0.5 * 0.5).Convert3D(-(Alist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(Alist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                        Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - (Alist[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.5 * 0.5), (Alist[i + 1] - 0.015 * 2 - 0.6) * 0.5, (Alist[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.5);
                        HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                    }
                    else  if (i == Alist.Count - 2)
                    {
                        DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                        DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(Alist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                        DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 , 0.5 * 0.5).Convert3D(-(Alist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(Alist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                        Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - (Alist[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.5 * 0.5), (Alist[i + 1] - 0.015 * 2 - 0.6) * 0.5, (Alist[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.5);
                        HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                    }
                }           
                else
                {
                    if (iaparas != null)
                    {
                        if (iaparas[1].Contains(i.ToString()))
                        {
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(Alist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5).Convert3D(-(Alist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(Alist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                            Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - (Alist[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.5 * 0.5), (Alist[i + 1] - 0.015 * 2 - 0.6) * 0.5, (Alist[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.5);
                            HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        }
                    }
                    else
                    {
                        if (i == 0)
                        {
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015 - 0.5, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                            //Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - 0.5 * 0.5, 0.25 * 0.5), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - 0.5 * 0.5, 0), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        }
                        else if (i == 1)
                        {
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5 + 0.015, 0.5 * 0.5), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(0.6 * 0.5 + 0.015, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5 + 0.015 + 0.5, 0.5 * 0.5), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                            //Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0.25 * 0.5), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        }
                        if (i == Alist.Count - 2)
                        {
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015 - 0.5, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                            //Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - 0.5 * 0.5, 0.25 * 0.5), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - 0.5 * 0.5, 0), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        }
                        else if (i == Alist.Count - 1)
                        {
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5 + 0.015, 0.5 * 0.5), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(0.6 * 0.5 + 0.015, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5 + 0.015 + 0.5, 0.5 * 0.5), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                            //Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0.25 * 0.5), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        }
                    }
                }
            }
            len = 0;
            for (int i = 0; i < Blist.Count; i++)
            {
                len += Blist[i];
                Point2d ptB = pt3.Convert2D(-len, h * 0.5);
                //PolylinePloter.AddPloy4(db, ref ext, ptB.Convert2D(0, 0.5 * 0.5), 0.6 * 0.5, 0.6 * 0.5, 0.5);
                //DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0.5 * 0.5 - 0.5).Convert3D(0, -0.35), scale);
                //DimPloter.DimAli(db, ref ext, ptB.Convert3D(0, 0.5 * 0.5), ptB.Convert3D(0, 0.5 * 0.5 - 0.5), ptB.Convert2D(-0.6 * 0.5, 0.5 * 0.5 - 0.5).Convert3D(-0.2), scale);
                _blcName = "pPlinth" + scale;
                dicA = new Dictionary<string, Dictionary<string, string>>();
                dicT = new Dictionary<string, string>();
                dicT.Add((i + 1).ToString(), "string");
                dicA.Add("A", dicT);
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(ptB.Convert3D(), 1, _blcName, _dwgPath, dicA, null, ref ext);
                if (piername.Contains("296")|| piername.Contains("297")|| piername.Contains("335") || piername.Contains("RP-15") || piername.Contains("RP-16") || piername.Contains("RP-17"))
                {
                    if (i == 0)
                    {
                        DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                        DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(Blist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                        DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 , 0.5 * 0.5).Convert3D(-(Blist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(Blist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                        Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - (Blist[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.5 * 0.5), (Blist[i + 1] - 0.015 * 2 - 0.6) * 0.5, (Blist[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.5);
                        HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        //DimPloter.AddMLeader(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0), ptB.Convert2D(0.6 * 0.5 + 0.5, -0.4), "Concrete buffer", tSize, scale);
                    }
                    else if (i == Blist.Count - 2)
                    {
                        DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                        DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(Blist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                        DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 , 0.5 * 0.5).Convert3D(-(Blist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(Blist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                        Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - (Blist[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.5 * 0.5), (Blist[i + 1] - 0.015 * 2 - 0.6) * 0.5, (Blist[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.5);
                        HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                    }
                }
               
                else
                {
                    if (iaparas != null)
                    {
                        if (iaparas[1].Contains(i.ToString()))
                        {
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(Blist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5).Convert3D(-(Blist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(Blist[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                            Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - (Blist[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.5 * 0.5), (Blist[i + 1] - 0.015 * 2 - 0.6) * 0.5, (Blist[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.5);
                            HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        }
                    }
                    else
                    {
                        if (i == 0)
                        {
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015 - 0.5, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                            //Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - 0.5 * 0.5, 0.25 * 0.5), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - 0.5 * 0.5, 0.25 ), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        }
                        else if (i == 1)
                        {
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5 + 0.015, 0.5 * 0.5), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(0.6 * 0.5 + 0.015, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5 + 0.015 + 0.5, 0.5 * 0.5), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                            //Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0.25 * 0.5), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0.25), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        }
                         if (i == Blist.Count - 2)
                        {
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015 - 0.5, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                            //Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - 0.5 * 0.5, 0.25 * 0.5), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - 0.5 * 0.5, 0.25 ), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        }
                        else if (i == Blist.Count - 1)
                        {
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5 + 0.015, 0.5 * 0.5), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.7 - tSize * 2), scale);
                            DimPloter.DimAli(db, ref ext, ptB.Convert3D(0.6 * 0.5 + 0.015, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5 + 0.015 + 0.5, 0.5 * 0.5), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                            //Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0.25 * 0.5), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0.25), 0.5 * 0.5, 0.5 * 0.5, 0.25);
                            HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        }
                    }
                }
            }
            #endregion

            #region //2、标注
            #region 外轮廓
          
            
            //左侧
            DimPloter.DimAli(db, ref ext, pt1.Convert3D(), pt2.Convert3D(), pt1.Convert3D(-1), scale);
            DimPloter.DimAli(db, ref ext, p00.Convert3D(), p01.Convert3D(), pt1.Convert3D(-0.5 ), scale);
            DimPloter.DimAli(db, ref ext, p1.Convert3D(), p01.Convert3D(), pt1.Convert3D(-0.5 ), scale);
            DimPloter.DimAli(db, ref ext, p0.Convert3D(), p1.Convert3D(), pt1.Convert3D(-0.5), scale);
            //右侧
            DimPloter.DimAli(db, ref ext, pt3.Convert3D(0, 0.5 * h ), pt4.Convert3D(0,-bottomW * 0.5), pt4.Convert3D(0.6), scale);
            DimPloter.DimAli(db, ref ext, pt4.Convert3D(0, -0.5 * h ), pt4.Convert3D(0, -bottomW * 0.5), pt4.Convert3D(0.6), scale);

            DimPloter.DimAli(db, ref ext, pt3.Convert3D(0, 0.5 * h), pt4.Convert3D(0, -0.5 * h), pt4.Convert3D(1.5), scale, "null");
            int pierNo = int.Parse(System.Text.RegularExpressions.Regex.Replace(piername, @"[^0-9]+", "").ToString());
            string stN = piername.Replace(pierNo.ToString(), "") + (pierNo - 1);
            string edN = piername.Replace(pierNo.ToString(), "") + (pierNo + 1);
            TextPloter.PlotText(db, ref ext, pt3.Convert3D(1.5, 0.5 * h - 0.2), edN, 1, tSize);
            TextPloter.PlotText(db, ref ext, pt4.Convert3D(1.5, -0.5 * h+0.05), stN, 1, tSize);
            TextPloter.PlotText(db, ref ext, pt4.Convert3D(1.5, -bottomW * 0.5), piername, 1, tSize);
            //下部
            DimPloter.DimAli(db, ref ext, pt2.Convert3D(), p00.Convert3D(), pt2.Convert3D(0,-0.5), scale);
            //上部
            DimPloter.DimAli(db, ref ext, pt4.Convert3D(-rside), pt1.Convert3D(side), pt1.Convert3D(0, 1.5 ), scale);
            DimPloter.DimAli(db, ref ext, pt1.Convert3D(), pt1.Convert3D(side), pt1.Convert3D(0, 1 ), scale);          
            DimPloter.DimAli(db, ref ext, pt4.Convert3D(-rside), pt4.Convert3D(), pt1.Convert3D(0, 1 ), scale);
            DimPloter.DimAli(db, ref ext, pt1.Convert3D(side), pt1.Convert3D(width*0.5), pt1.Convert3D(0, 1 ), scale);
            DimPloter.DimAli(db, ref ext,  pt1.Convert3D(width * 0.5), pt4.Convert3D(-rside), pt1.Convert3D(0, 1 ), scale);
            #endregion
            double len1 = 0;
            double len2 = 0;
            #region 垫石
            for (int i=0;i< Alist.Count;i++)
            {
               
                if(i>0)
                  len1 += Alist[i-1];
                len2 += Alist[i];
                if (i==0)
                    DimPloter.DimAli(db, ref ext, pt4.Convert3D(), pt4.Convert3D(-len2), pt1.Convert3D(0, 0.5 ), scale);
                else 
                {
                    DimPloter.DimAli(db, ref ext, pt4.Convert3D(-len2), pt4.Convert3D(-len1), pt1.Convert3D(0, 0.5 ), scale);
                }
                if (i ==Alist.Count - 1)
                    DimPloter.DimAli(db, ref ext, pt1.Convert3D(), pt4.Convert3D(-len2), pt1.Convert3D(0, 0.5 ), scale);
                //TextPloter.PlotText(db, ref ext, pt4.Convert3D(-len2-0.4, 0.1), txt, 1, 0.15);

               
            }
            len1 = 0;
            len2 = 0;
            for (int i = 0; i < Blist.Count; i++)
            {
               
                if (i > 0)
                    len1 += Blist[i - 1];
                len2 += Blist[i];
                if (i == 0)
                    DimPloter.DimAli(db, ref ext, pt3.Convert3D(), pt3.Convert3D(-len2), pt2.Convert3D(0, -1 ), scale);
                else
                {
                    DimPloter.DimAli(db, ref ext, pt3.Convert3D(-len2), pt3.Convert3D(-len1), pt2.Convert3D(0, -1 ), scale);
                }
                if (i == Blist.Count - 1)
                    DimPloter.DimAli(db, ref ext, pt2.Convert3D(), pt3.Convert3D(-len2), pt2.Convert3D(0, -1 ), scale);

            }
            #endregion

            #endregion

            #endregion

            #region 立面I绘制
            CreateAB(db, ref extA, startAPoint, Extensions.curFont, scale, tr, Alist,_dwgPath, plinthCoorPath, iaparas, ibparas, taparas, tbparas, "Ⅰ-Ⅰ",title);
            #endregion

            #region 立面II绘制
            CreateAB(db, ref extB, startBPoint, Extensions.curFont, scale, tr, Blist, _dwgPath, plinthCoorPath, iaparas, ibparas, taparas, tbparas, "Ⅱ-Ⅱ", title);
            #endregion

            CreateBS(db, ref extC, startCPoint, Extensions.curFont, scale, tr, _dwgPath);
        }

        public static void CreateAB(Database db, ref Extents2d ext, Point3d startPoint,
string txtStyle, double scale, System.Data.DataRow tr,List<double> lst, string _dwgPath, string plinthCoorPath, string[] iaparas, string[] ibparas, string[] taparas, string[] tbparas, string title= "Ⅰ-Ⅰ",string location= "MAINLINE")
        {
            //System.Data.DataTable dt = CVSTools.OpenCSV(@"C:\Users\huajie\Documents\WeChat Files\wxid_1fmp3vdht5sl22\FileStorage\File\2021-12\P-295-P-335垫石坐标.csv");
            //System.Data.DataTable dt = CVSTools.OpenCSV(@"C:\Users\huajie\Documents\WXWork\1688856441293541\Cache\File\2022-01\Banani EX-2 垫石坐标(1).csv");
            System.Data.DataTable dt = CVSTools.OpenCSV(plinthCoorPath);
            DataView dv0 = dt.DefaultView;
            dt = dv0.ToTable(true, new string[] { "Pier", "Side", "PlinthNo", "East", "North", "Height", "H0" });
         
            double tSize = 0.15;
            if (scale == 80)
                tSize = (2 * scale) / 1000;
            else if (scale == 100)
                tSize = (2 * scale) / 1000;
            else
                tSize = (2 * scale) / 1000;
            //double width = double.Parse(tr["总墩距"].ToString());
            double lwidth = double.Parse(tr["左墩距"].ToString());
            double side = double.Parse(tr["左边距"].ToString());
            double rside = double.Parse(tr["右边距"].ToString());
            double width = double.Parse(tr["总墩距"].ToString()) + rside + side;
            double bottomW = double.Parse(tr["底宽"].ToString());
            double topW = double.Parse(tr["顶宽"].ToString());
            double height = double.Parse(tr["总高"].ToString());
            double calculatedHeight = double.Parse(tr["底高"].ToString());
            double plinthHeight = double.Parse(tr["支座距"].ToString());
            string piername = tr["墩号"].ToString();
            string piertype = tr["墩柱类别"].ToString();
            //string AString = tr["垫石A"].ToString();
            //string BString = tr["垫石B"].ToString();
            double radius = 0.2;

            double pierW = 1.2;

            DataRow[] drsA = dt.Select("Pier='" + piername + "' and Side='A' and( PlinthNo like '%-1' or PlinthNo like '%月1日'   or  PlinthNo like '1月13日' or  PlinthNo like '1月14日' or  PlinthNo like '1月15日' or  PlinthNo like '1月16日' or  PlinthNo like '1月17日' or  PlinthNo like '1月18日' or  PlinthNo like '1月19日' or  PlinthNo like '1月20日')");
            if(title == "Ⅰ-Ⅰ")
                drsA = dt.Select("Pier='" + piername + "' and Side='A' and ( PlinthNo like '%-1' or PlinthNo like '%月1日'   or  PlinthNo like '1月13日' or  PlinthNo like '1月14日' or  PlinthNo like '1月15日' or  PlinthNo like '1月16日' or  PlinthNo like '1月17日' or  PlinthNo like '1月18日' or  PlinthNo like '1月19日' or  PlinthNo like '1月20日')");
            else
                drsA = dt.Select("Pier='" + piername + "' and Side='B' and (PlinthNo like '%-1' or PlinthNo like '%月1日'   or  PlinthNo like '1月13日' or  PlinthNo like '1月14日' or  PlinthNo like '1月15日' or  PlinthNo like '1月16日' or  PlinthNo like '1月17日' or  PlinthNo like '1月18日' or  PlinthNo like '1月19日' or  PlinthNo like '1月20日')");

            System.Data.DataTable dt0 = dt.Clone();
            foreach (DataRow item in drsA)
            {
                dt0.Rows.Add(item.ItemArray);
            }
            Dictionary<string, Dictionary<string, string>> dicA = new Dictionary<string, Dictionary<string, string>>();
            Dictionary<string, string> dicT = new Dictionary<string, string>();

            dicT = new Dictionary<string, string>();
            string _blcName = "";
            #region 1.外轮廓绘制

            string str1 = title + " FOR " + piername + " OF "+ location;
            string str2 = "1:" + scale + "@A3";
            TextPloter.PrintScaleDoubleSideTextNew(db, startPoint.Convert2D(0, 2), tSize * 1.25, str1, str2, ref ext, 1, Extensions.curFont);
            //1、绘制
            List<Point2d> ptL = new List<Point2d>();
            Point2d pt1 = startPoint.Convert2D(-width * 0.5);
            Point2d pt2 = pt1.Convert2D(0, -height+radius);
            Point2d pt3 = pt2.Convert2D(width);
            Point2d pt4 = pt3.Convert2D(0, height- radius);
            Point2d pt0 = pt3.Convert2D(0, -radius);
            ptL.Add(pt2);
            ptL.Add(pt1);
            ptL.Add(pt4);
            ptL.Add(pt3);
            PolylinePloter.AddPolylineByList(db, ref ext, ptL, "细线", 4, false);

            PolylinePloter.CreateArc(db, ref ext, pt2.Convert3D(radius), radius, 180, 270);
            PolylinePloter.CreateArc(db, ref ext, pt3.Convert3D(-radius), radius,270,0);
            double w = side - pierW * 0.5;
            double rw = rside - pierW * 0.5;
            if (w < 0)
                w = 0;
            if (rw < 0)
                rw = 0;
            PolylinePloter.AddPolyline(db, ref ext, pt2.Convert2D(radius, -radius), pt2.Convert2D(w, -radius), 0, 0, 0, 0, "细线", 4);
            PolylinePloter.AddPolyline(db, ref ext, pt2.Convert2D(w, -radius), pt2.Convert2D(w, -radius - 1), 0, 0, 0, 0, "细线", 4);
            PolylinePloter.AddPolyline(db, ref ext, pt2.Convert2D(w + pierW, -radius), pt2.Convert2D(w + pierW, -radius - 1), 0, 0, 0, 0, "细线", 4);
     
            PolylinePloter.AddPolyline(db, ref ext, pt3.Convert2D(-radius, -radius), pt3.Convert2D(-rw, -radius), 0, 0, 0, 0, "细线", 4);
            PolylinePloter.AddPolyline(db, ref ext, pt3.Convert2D(-rw, -radius), pt3.Convert2D(-rw, -radius - 1), 0, 0, 0, 0, "细线", 4);
            PolylinePloter.AddPolyline(db, ref ext, pt3.Convert2D(-rw - pierW, -radius), pt3.Convert2D(-rw - pierW, -radius - 1), 0, 0, 0, 0, "细线", 4);

            PolylinePloter.AddPolyline(db, ref ext, pt3.Convert2D(-rw - pierW, -radius), pt2.Convert2D(w + pierW, -radius), 0, 0, 0, 0, "细线", 4);

            PolylinePloter.CreateBreakLine(db, ref ext, pt2.Convert2D(-0.5 +w+ radius, -radius - 1), pt2.Convert2D(w + pierW + 0.5, -radius - 1), 1);
            PolylinePloter.CreateBreakLine(db, ref ext, pt3.Convert2D(-rw - pierW - 0.5, -radius - 1), pt3.Convert2D(-rw + 0.5, -radius - 1), 1);

            //PolylinePloter.AddPolyline(db, ref ext, pt2.Convert2D(radius, -radius), pt2.Convert2D(radius, -radius - 1), 0, 0, 0, 0, "细线", 4);
            //PolylinePloter.AddPolyline(db, ref ext, pt2.Convert2D(radius + pierW, -radius), pt2.Convert2D(radius+ pierW, -radius - 1), 0, 0, 0, 0, "细线", 4);
            //PolylinePloter.AddPolyline(db, ref ext, pt3.Convert2D(-radius, -radius), pt3.Convert2D(-radius, -radius - 1), 0, 0, 0, 0, "细线", 4);
            //PolylinePloter.AddPolyline(db, ref ext, pt3.Convert2D(-radius - pierW, -radius), pt3.Convert2D(-radius - pierW, -radius - 1), 0, 0, 0, 0, "细线", 4);
            //PolylinePloter.AddPolyline(db, ref ext, pt3.Convert2D(-radius - pierW, -radius), pt2.Convert2D(radius + pierW, -radius), 0, 0, 0, 0, "细线", 4);
      
            //PolylinePloter.CreateBreakLine(db, ref ext, pt2.Convert2D(-0.5+radius, -radius - 1), pt2.Convert2D(radius + pierW+0.5, -radius - 1), 1);
            //PolylinePloter.CreateBreakLine(db, ref ext, pt3.Convert2D(-radius - pierW-0.5, -radius - 1), pt3.Convert2D(-radius+0.5, -radius - 1), 1);
            //res.Add(arc1);

            ptL = new List<Point2d>();
            double h = (height - calculatedHeight);
            Point2d p0 = pt1.Convert2D(0.2, 0);
            Point2d p1 = p0.Convert2D(0, -h);
            Point2d p2 = p1.Convert2D(width - 0.4, 0);
            Point2d p3 = p2.Convert2D(0, h);
            ptL.Add(p0);
            ptL.Add(p1);
            ptL.Add(p2);
            ptL.Add(p3);
            PolylinePloter.AddPolylineByList(db, ref ext, ptL, "细线", 4, false);
            _blcName = "CL";
            PolylinePloter.AddPolyline(db, ref ext, pt1.Convert2D(side, 0.6), pt2.Convert2D(side, -1.3), 0, 0, 0, 0, "中心线", 5, 2.5);
            dicA = new Dictionary<string, Dictionary<string, string>>();
            dicT = new Dictionary<string, string>();
            dicT.Add("Column", "string");
            dicA.Add("CL", dicT);
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(pt1.Convert3D(side, 0.4), tSize * 2, _blcName, _dwgPath, dicA, null, ref ext);
            PolylinePloter.AddPolyline(db, ref ext, startPoint.Convert2D(0, 0.6), startPoint.Convert2D(0, -bottomW), 0, 0, 0, 0, "中心线", 5, 2.5);
            dicA = new Dictionary<string, Dictionary<string, string>>();
            dicT = new Dictionary<string, string>();
            dicT.Add("Cross Beam", "string");
            dicA.Add("CL", dicT);
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(startPoint.Convert3D(0, 0.4), tSize * 2, _blcName, _dwgPath, dicA, null, ref ext);
            PolylinePloter.AddPolyline(db, ref ext, pt3.Convert2D(-rside, -1.3), pt4.Convert2D(-rside, 0.4), 0, 0, 0, 0, "中心线", 5, 2.5);
            dicA = new Dictionary<string, Dictionary<string, string>>();
            dicT = new Dictionary<string, string>();
            dicT.Add("Column", "string");
            dicA.Add("CL", dicT);
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(pt4.Convert3D(-rside- tSize * 4.5, 0.4), tSize * 2, _blcName, _dwgPath, dicA, null, ref ext);

            //2、标注
            if (!DimStyleTool.CheckDimStyleExists(scale))
            {
                DimStyleTool.CreateModifyDimStyle(scale);
            }
            ////左侧
            //DimPloter.DimAli(db, ref ext, pt1.Convert3D(), pt2.Convert3D(), pt1.Convert3D(-1 * scale), scale);
            //DimPloter.DimAli(db, ref ext, p00.Convert3D(), p01.Convert3D(), pt1.Convert3D(-0.5 * scale), scale);
            //DimPloter.DimAli(db, ref ext, p1.Convert3D(), p01.Convert3D(), pt1.Convert3D(-0.5 * scale), scale);
            //DimPloter.DimAli(db, ref ext, p0.Convert3D(), p1.Convert3D(), pt1.Convert3D(-0.5 * scale), scale);
            ////右侧
            //DimPloter.DimAli(db, ref ext, pt3.Convert3D(), pt4.Convert3D(), pt4.Convert3D(1 * scale), scale);
            //DimPloter.DimAli(db, ref ext, p02.Convert3D(), p03.Convert3D(), pt4.Convert3D(0.5 * scale), scale);
            //DimPloter.DimAli(db, ref ext, p2.Convert3D(), p02.Convert3D(), pt4.Convert3D(0.5 * scale), scale);
            //DimPloter.DimAli(db, ref ext, p2.Convert3D(), p3.Convert3D(), pt4.Convert3D(0.5 * scale), scale);


            ////下部
            //DimPloter.DimAli(db, ref ext, pt2.Convert3D(), p00.Convert3D(), pt2.Convert3D(0, -0.5 * scale), scale);
            ////上部
            //DimPloter.DimAli(db, ref ext, pt4.Convert3D(-side), pt1.Convert3D(side), pt1.Convert3D(0, 1.5 * scale), scale);
            //DimPloter.DimAli(db, ref ext, pt1.Convert3D(), pt1.Convert3D(side), pt1.Convert3D(0, 1 * scale), scale);
            //DimPloter.DimAli(db, ref ext, pt4.Convert3D(-side), pt4.Convert3D(), pt1.Convert3D(0, 1 * scale), scale);
            //DimPloter.DimAli(db, ref ext, pt1.Convert3D(side), pt1.Convert3D(width * 0.5), pt1.Convert3D(0, 1 * scale), scale);
            //DimPloter.DimAli(db, ref ext, pt1.Convert3D(width * 0.5), pt4.Convert3D(-side), pt1.Convert3D(0, 1 * scale), scale);
            #endregion
            #region 垫石绘制
            double len = 0;
            for (int i = 0; i < lst.Count; i++)
            {
                len += lst[i];
                Point2d ptB = pt0.Convert2D(-len, calculatedHeight);
               
                _blcName = "vPlinth" + scale;
                Dictionary<string, Dictionary<string, string>> dicb = new Dictionary<string, Dictionary<string, string>>();
                dicA = new Dictionary<string, Dictionary<string, string>>();
                dicT = new Dictionary<string, string>();
                dicT.Add((i + 1).ToString(), "string");
                dicA.Add("A", dicT);
                if (i < drsA.Length)
                {
                    DataRow[] dr;
                    if (i<12)
                        dr = dt0.Select("PlinthNo like '" + (i + 1) + "-%'  or PlinthNo like '" + (i + 1) + "月1日'");
                    else
                       dr = dt0.Select(" PlinthNo like '1月13日' or PlinthNo like '1月14日' or PlinthNo like '1月15日' or PlinthNo like '1月16日' or PlinthNo like '1月17日' or PlinthNo like '1月18日' or PlinthNo like '1月19日' or PlinthNo like '1月20日' ");
                    //PlinthNo like '%-1' or PlinthNo like '%月1日'   or PlinthNo like '1月13日' or PlinthNo like '1月14日' or PlinthNo like '1月15日' or PlinthNo like '1月16日' or PlinthNo like '1月17日' or PlinthNo like '1月18日' or PlinthNo like '1月19日' or PlinthNo like '1月20日')
                    dicT = new Dictionary<string, string>();
                    if (dr != null && dr.Length > 0)
                    {
                        dicT.Add(double.Parse(dr[0]["Height"].ToString()).ToString("0.000"), "double");
                        dicb.Add("距离1", dicT);
                    }
                    else
                    {

                    }
                  
                }
                db.CopyBlockFromFile(_dwgPath, _blcName);
                BlockTool.InsertBlockReference(ptB.Convert3D(0.3,-0.454), 1, _blcName, _dwgPath, dicA, dicb, ref ext);
                //DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5, 0.5 * 0.5), ptB.Convert2D(-0.6*0.5, 0.5 * 0.5 - 0.5).Convert3D(0,-0.35), scale);
                //DimPloter.DimAli(db, ref ext, ptB.Convert3D(0, 0.5 * 0.5), ptB.Convert3D(0, 0.5 * 0.5 - 0.5), ptB.Convert2D(-0.6 * 0.5, 0.5 * 0.5 - 0.5).Convert3D(-0.2), scale);
                //挡块
                if (title == "Ⅰ-Ⅰ")
                {
                    if (piername.Contains("297") || piername.Contains("298"))
                    {
                        if (i == 0)
                        {
                            //DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0.5 * 0.5 - 0.5).Convert3D(0, -0.15), scale);
                            //DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(lst[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                            //DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5).Convert3D(-(lst[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(lst[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(0.6 * 0.5, 0.5 * 0.5 - 0.5).Convert3D(0, -0.15), scale);
                            Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.6), (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.6);
                            HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        }
                        else if (i == lst.Count - 2)
                        {
                            //DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0.5 * 0.5 - 0.5).Convert3D(0, -0.15), scale);
                            //DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(lst[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.7), scale);
                            //DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5).Convert3D(-(lst[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5).Convert3D(-(lst[i + 1] - 0.015 * 2 - 0.6)), ptB.Convert2D(0.6 * 0.5, 0.5 * 0.5 - 0.5).Convert3D(0, -0.15), scale);
                            Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.6), (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.6);
                            HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        }
                    }
                    else
                    {
                        if (iaparas != null)
                        {
                            if (iaparas[1].Contains(i.ToString()))
                            {
                                Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.6), (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.6);
                                HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                                if (i == 0)
                                    DimPloter.AddMLeader(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - (lst[i + 1] - 0.015 * 2 - 0.6) * 0.8, 0), ptB.Convert2D(-0.6 * 0.5 - 0.015 - (lst[i + 1] - 0.015 * 2 - 0.6) * 0.8 + 0.5, -0.4), "Concrete buffer", tSize, scale);
                            }
                        }
                        else
                        {
                            if (taparas != null)
                            {
                                if (taparas[1].Contains(i.ToString()))
                                {
                                    List<string> lt = taparas[1].Split(',').ToList();
                                    for (int no = 0; no < lt.Count; no++)
                                    {
                                        if (lt[no] == i.ToString())
                                        {
                                            if (no % 2 == 0)
                                            {
                                                Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - 0.5 * 0.5, 0.6), 0.5 * 0.5, 0.5 * 0.5, 0.6);
                                                HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                                            }
                                            else
                                            {
                                                Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0.6), 0.5 * 0.5, 0.5 * 0.5, 0.6);
                                                HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                                                if (no == 1)
                                                    DimPloter.AddMLeader(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0), ptB.Convert2D(0.6 * 0.5 + 0.5, -0.4), "Concrete buffer", tSize, scale);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (i == 0)
                                {
                                    //DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0.5 * 0.5 - 0.5).Convert3D(0, 0), scale);
                                    //DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015 - 0.5, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.368), scale);
                                    Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - 0.5 * 0.5, 0.6), 0.5 * 0.5, 0.5 * 0.5, 0.6);
                                    HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                                }
                                else if (i == 1)
                                {
                                    //DimPloter.DimAli(db, ref ext, ptB.Convert3D(0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5 + 0.015, 0.5 * 0.5), ptB.Convert2D(0.6 * 0.5, 0.5 * 0.5 - 0.5).Convert3D(0, 0), scale);
                                    //DimPloter.DimAli(db, ref ext, ptB.Convert3D(0.6 * 0.5 + 0.015, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5 + 0.015 + 0.5, 0.5 * 0.5), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.368), scale);
                                    Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0.6), 0.5 * 0.5, 0.5 * 0.5, 0.6);
                                    HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);

                                    DimPloter.AddMLeader(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0.6), ptB.Convert2D(0.6 * 0.5 + 1, 1.3), "Concrete buffer", tSize * 1.5, scale);
                                }
                                 if (i == lst.Count - 2)
                                {
                                    //DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0.5 * 0.5 - 0.5).Convert3D(0, 0), scale);
                                    //DimPloter.DimAli(db, ref ext, ptB.Convert3D(-0.6 * 0.5 - 0.015, 0.5 * 0.5), ptB.Convert3D(-0.6 * 0.5 - 0.015 - 0.5, 0.5 * 0.5), ptB.Convert2D(-0.6 * 0.5, 0).Convert3D(0, -0.368), scale);
                                    Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - 0.5 * 0.5, 0.6), 0.5 * 0.5, 0.5 * 0.5, 0.6);
                                    HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                                }
                                else if (i == lst.Count - 1)
                                {
                                    //DimPloter.DimAli(db, ref ext, ptB.Convert3D(0.6 * 0.5, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5 + 0.015, 0.5 * 0.5), ptB.Convert2D(0.6 * 0.5, 0.5 * 0.5 - 0.5).Convert3D(0, 0), scale);
                                    //DimPloter.DimAli(db, ref ext, ptB.Convert3D(0.6 * 0.5 + 0.015, 0.5 * 0.5), ptB.Convert3D(0.6 * 0.5 + 0.015 + 0.5, 0.5 * 0.5), ptB.Convert2D(0.6 * 0.5, 0).Convert3D(0, -0.368), scale);
                                    Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0.6), 0.5 * 0.5, 0.5 * 0.5, 0.6);
                                    HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (piername.Contains("296") || piername.Contains("297") || piername.Contains("335"))
                    {
                        if (i == 0)
                        {                            
                            Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.6), (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.6);
                            HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        }
                        else if (i == lst.Count - 2)
                        {                           
                            Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.6), (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.6);
                            HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                        }
                    }
                    else
                    {
                        if (ibparas != null)
                        {
                            if (ibparas[1].Contains(i.ToString()))
                            {
                                Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.6), (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, (lst[i + 1] - 0.015 * 2 - 0.6) * 0.5, 0.6);
                                HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                                if (i == 0)
                                    DimPloter.AddMLeader(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - (lst[i + 1] - 0.015 * 2 - 0.6) * 0.8, 0), ptB.Convert2D(-0.6 * 0.5 - 0.015 - (lst[i + 1] - 0.015 * 2 - 0.6) * 0.8 + 0.5, -0.4), "Concrete buffer", tSize, scale);
                            }
                        }
                        else
                        {
                            if (tbparas != null)
                            {
                                if (tbparas[1].Contains(i.ToString()))
                                {
                                    List<string> lt = tbparas[1].Split(',').ToList();
                                    for (int no = 0; no < lt.Count; no++)
                                    {
                                        if (lt[no] == i.ToString())
                                        {
                                            if (no % 2 == 0)
                                            {
                                                Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - 0.5 * 0.5, 0.6), 0.5 * 0.5, 0.5 * 0.5, 0.6);
                                                HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                                            }
                                            else
                                            {
                                                Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0.6), 0.5 * 0.5, 0.5 * 0.5, 0.6);
                                                HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                                                if (no == 1)
                                                    DimPloter.AddMLeader(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0), ptB.Convert2D(0.6 * 0.5 + 0.5, -0.4), "Concrete buffer", tSize, scale);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (i == 0)
                                {
                                    Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - 0.5 * 0.5, 0.6), 0.5 * 0.5, 0.5 * 0.5, 0.6);
                                    HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                                }
                                else if (i == 1)
                                {
                                    Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0.6), 0.5 * 0.5, 0.5 * 0.5, 0.6);
                                    HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);

                                    DimPloter.AddMLeader(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0.6), ptB.Convert2D(0.6 * 0.5 + 1, 1.3), "Concrete buffer", tSize * 1.5, scale);
                                }
                                 if (i == lst.Count - 2)
                                {
                                    Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(-0.6 * 0.5 - 0.015 - 0.5 * 0.5, 0.6), 0.5 * 0.5, 0.5 * 0.5, 0.6);
                                    HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                                }
                                else if (i == lst.Count - 1)
                                {
                                    Polyline pl = PolylinePloter.GetPLAddPloy4(db, ref ext, ptB.Convert2D(0.6 * 0.5 + 0.015 + 0.5 * 0.5, 0.6), 0.5 * 0.5, 0.5 * 0.5, 0.6);
                                    HatchPloter.HatchEnity(HostApplicationServices.WorkingDatabase, "ANSI31", 0.04, 0, pl.ObjectId);
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            #region 
            //左侧
            DimPloter.DimAli(db, ref ext, pt1.Convert3D(), pt0.Convert3D(-width), pt1.Convert3D(-1), scale);
            DimPloter.DimAli(db, ref ext, pt1.Convert3D(0, -h), pt1.Convert3D(), pt1.Convert3D(-0.5), scale);
            DimPloter.DimAli(db, ref ext, pt0.Convert3D(-width), pt1.Convert3D(0, -h), pt1.Convert3D(-0.5), scale);

            //上部
            DimPloter.DimAli(db, ref ext, pt4.Convert3D(-rside), pt1.Convert3D(side), pt1.Convert3D(0, 1.5), scale);
            DimPloter.DimAli(db, ref ext, pt1.Convert3D(), pt1.Convert3D(side), pt1.Convert3D(0, 1.2), scale);
            DimPloter.DimAli(db, ref ext, pt4.Convert3D(-rside), pt4.Convert3D(), pt1.Convert3D(0, 1.2), scale);
            DimPloter.DimAli(db, ref ext, pt1.Convert3D(side), pt1.Convert3D(width * 0.5), pt1.Convert3D(0, 1.2), scale);
            DimPloter.DimAli(db, ref ext, pt1.Convert3D(width * 0.5), pt4.Convert3D(-rside), pt1.Convert3D(0, 1.2), scale);
            DimPloter.DimAli(db, ref ext, pt1.Convert3D(), pt1.Convert3D(radius), pt1.Convert3D(0, 0.8), scale);
            DimPloter.DimAli(db, ref ext, pt4.Convert3D(-radius), pt4.Convert3D(), pt1.Convert3D(0, 0.8), scale);
            double len1 = 0;
            double len2 = 0;
            #region 垫石
            for (int i = 0; i < lst.Count; i++)
            {

                if (i > 0)
                    len1 += lst[i - 1];
                len2 += lst[i];
                if (i == 0)
                    DimPloter.DimAli(db, ref ext, pt4.Convert3D(), pt4.Convert3D(-len2), pt1.Convert3D(0, -tSize*2), scale);
                else
                {
                    DimPloter.DimAli(db, ref ext, pt4.Convert3D(-len2), pt4.Convert3D(-len1), pt1.Convert3D(0, -tSize * 2), scale);
                }
                if (i == lst.Count - 1)
                    DimPloter.DimAli(db, ref ext, pt1.Convert3D(), pt4.Convert3D(-len2), pt1.Convert3D(0, -tSize * 2), scale);
                //TextPloter.PlotText(db, ref ext, pt4.Convert3D(-len2-0.4, 0.1), txt, 1, 0.15);


            }
            #endregion
            #endregion
        }

        public static void CreateBS(Database db, ref Extents2d ext, Point3d startPoint,
string txtStyle, double scale, System.Data.DataRow tr,  string _dwgPath)
        {
            double tSize = 0.15;
            if (scale == 80)
                tSize = (2 * scale) / 1000;
            else if (scale == 100)
                tSize = (2 * scale) / 1000;
            else
                tSize = (2 * scale) / 1000;

            double bottomW = double.Parse(tr["底宽"].ToString());
            double topW = double.Parse(tr["顶宽"].ToString());
            double height = double.Parse(tr["总高"].ToString());
            double calculatedHeight = double.Parse(tr["底高"].ToString());
            double plinthHeight = double.Parse(tr["支座距"].ToString());
            string piername = tr["墩号"].ToString();
            string piertype = tr["墩柱类别"].ToString();
            double h = (height - calculatedHeight);
            double w = (bottomW - topW)*0.5;
            double radius = 0.2;

            double pierW = 1.2;
            int pierNo = int.Parse(System.Text.RegularExpressions.Regex.Replace(piername, @"[^0-9]+", "").ToString());
            string stN = piername.Replace(pierNo.ToString(), "") + (pierNo - 1);
            string edN = piername.Replace(pierNo.ToString(), "") + (pierNo + 1);
            Dictionary<string, Dictionary<string, string>> dicA = new Dictionary<string, Dictionary<string, string>>();
            Dictionary<string, string> dicT = new Dictionary<string, string>();

            dicT = new Dictionary<string, string>();
            string _blcName = "";
            #region 1.外轮廓绘制

            string str1 = string.Format("PIER TYPE \"{0}\" (SIDE VIEW) ", piertype);
            string str2 = "1:" + scale + "@A3";
            TextPloter.PrintScaleDoubleSideTextNew(db, startPoint.Convert2D(0, 2), tSize * 1.25, str1, str2, ref ext, 1, Extensions.curFont);
            Line2d line = new Line2d(startPoint.Convert2D(),startPoint.Convert2D(0,-height));
            //1、绘制
            List<Point2d> ptL = new List<Point2d>();
            Point2d pt1 = startPoint.Convert2D(-topW*0.5+0.02);
            Point2d pt2 = pt1.Convert2D(-0.02,-0.02);
            Point2d pt3 = pt2.Convert2D(0,-h+0.02*2);
            Point2d pt4 = pt3.Convert2D(-0.02, -0.02);
            Point2d pt5 = pt4.Convert2D(-w+0.02*2, 0);
            Point2d pt6 = pt5.Convert2D(- 0.02, -0.02);
            Point2d pt7 = pt6.Convert2D(0, -calculatedHeight + 0.02 * 2);
            Point2d pt8 = pt7.Convert2D(0.02, -0.02 );
            Point2d pt9 = pt8.Mirror(line);
            Point2d pt10 = pt7.Mirror(line);
            Point2d pt11 = pt6.Mirror(line);
            Point2d pt12 = pt5.Mirror(line);
            Point2d pt13 = pt4.Mirror(line);
            Point2d pt14 = pt3.Mirror(line);
            Point2d pt15 = pt2.Mirror(line);
            Point2d pt16 = pt1.Mirror(line);
            //Point2d pt0 = pt3.Convert2D(0, -radius);
          
            ptL.Add(pt1);
            ptL.Add(pt2);
            ptL.Add(pt3);
            ptL.Add(pt4);
            ptL.Add(pt5);
            ptL.Add(pt6);
            ptL.Add(pt7);
            ptL.Add(pt8);
            ptL.Add(pt9);
            ptL.Add(pt10);
            ptL.Add(pt11);
            ptL.Add(pt12);
            ptL.Add(pt13);
            ptL.Add(pt14);
            ptL.Add(pt15);
            ptL.Add(pt16);
            PolylinePloter.AddPolylineByList(db, ref ext, ptL, "细线", 4, true);

            PolylinePloter.AddPolyline(db, ref ext, startPoint.Convert2D(-topW*0.6,-height), startPoint.Convert2D(-topW * 0.6, -height - 1), 0, 0, 0, 0, "细线", 4);
            PolylinePloter.AddPolyline(db, ref ext, startPoint.Convert2D(topW * 0.6, -height), startPoint.Convert2D(topW * 0.6, -height - 1), 0, 0, 0, 0, "细线", 4);

            PolylinePloter.CreateBreakLine(db, ref ext, startPoint.Convert2D(-topW * 0.6-0.5, -height-1), startPoint.Convert2D(topW * 0.6+0.5, -height - 1), 1);

            _blcName = "CL";
            Point3d pt = GeTools.MidPoint(pt4.Convert3D(), pt5.Convert3D());
            PolylinePloter.AddPolyline(db, ref ext, pt.Convert2D(), pt.Convert2D(0,h+0.5), 0, 0, 0, 0, "中心线", 5, 2.5);
            dicA = new Dictionary<string, Dictionary<string, string>>();
            dicT = new Dictionary<string, string>();
            dicT.Add("Bearing", "string");
            dicA.Add("CL", dicT);
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(pt.Convert3D(-tSize * 2, h + 0.5), tSize * 2, _blcName, _dwgPath, dicA, null, ref ext);
            _blcName = "bearP";         
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(pt.Convert3D(), 1, _blcName, _dwgPath, null, null, ref ext);

            _blcName = "CL";
            PolylinePloter.AddPolyline(db, ref ext, startPoint.Convert2D(0, 0.5), startPoint.Convert2D(0, -height-1.1), 0, 0, 0, 0, "中心线", 5, 2.5);
            dicA = new Dictionary<string, Dictionary<string, string>>();
            dicT = new Dictionary<string, string>();
            dicT.Add("Pier", "string");
            dicA.Add("CL", dicT);
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(startPoint.Convert3D(-tSize*0.5, 0.5), tSize * 2, _blcName, _dwgPath, dicA, null, ref ext);

            _blcName = "CL";
            Point3d pt0 = GeTools.MidPoint(pt12.Convert3D(), pt13.Convert3D());
            PolylinePloter.AddPolyline(db, ref ext, pt0.Convert2D(), pt0.Convert2D(0, h + 0.5), 0, 0, 0, 0, "中心线", 5, 2.5);
            dicA = new Dictionary<string, Dictionary<string, string>>();
            dicT = new Dictionary<string, string>();
            dicT.Add("Bearing", "string");
            dicA.Add("CL", dicT);
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(pt0.Convert3D(0, h + 0.5), tSize * 2, _blcName, _dwgPath, dicA, null, ref ext);

            _blcName = "bearP";
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(pt0.Convert3D(), 1, _blcName, _dwgPath, null, null, ref ext);

            _blcName = "PNO";
            dicA = new Dictionary<string, Dictionary<string, string>>();
            dicT = new Dictionary<string, string>();
            dicT.Add(stN, "string");
            dicA.Add("ST", dicT);
            dicT = new Dictionary<string, string>();
            dicT.Add(piername, "string");
            dicA.Add("NO", dicT);
            dicT = new Dictionary<string, string>();
            dicT.Add(edN, "string");
            dicA.Add("ED", dicT);
            db.CopyBlockFromFile(_dwgPath, _blcName);
            BlockTool.InsertBlockReference(startPoint.Convert3D(0, -height - 1.2), 1*scale/80.0, _blcName, _dwgPath, dicA, null, ref ext);
            //2、标注
            if (!DimStyleTool.CheckDimStyleExists(scale))
            {
                DimStyleTool.CreateModifyDimStyle(scale);
            }

            #endregion
            #region 垫石绘制

            #endregion

            #region 
            //左侧
            DimPloter.DimRotated(db, ref ext, pt1.Convert3D(), pt8.Convert3D(), startPoint.Convert3D(-bottomW*0.5-1), scale, 90);
            DimPloter.DimRotated(db, ref ext, pt1.Convert3D(), pt4.Convert3D(), startPoint.Convert3D(-bottomW * 0.5 - 0.5), scale, 90);
            DimPloter.DimRotated(db, ref ext, pt4.Convert3D(), pt8.Convert3D(), startPoint.Convert3D(-bottomW * 0.5 - 0.5), scale, 90);

            //上部
            DimPloter.DimRotated(db, ref ext, pt6.Convert3D(), pt11.Convert3D(), startPoint.Convert3D(0, 1.5), scale);
            DimPloter.DimRotated(db, ref ext, pt2.Convert3D(), pt6.Convert3D(), startPoint.Convert3D(0, 1), scale);
            DimPloter.DimRotated(db, ref ext, pt2.Convert3D(), pt15.Convert3D(), startPoint.Convert3D(0, 1), scale);
            DimPloter.DimRotated(db, ref ext, pt11.Convert3D(), pt15.Convert3D(), startPoint.Convert3D(0, 1), scale);


            DimPloter.DimRotated(db, ref ext, pt.Convert3D(), startPoint.Convert3D(), startPoint.Convert3D(0, -1), scale);
            DimPloter.DimRotated(db, ref ext, pt0.Convert3D(), startPoint.Convert3D(), startPoint.Convert3D(0, -1), scale);
            #endregion
        }
    }
}
